package com.apps.config;

import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * 微信支付的配置文件
 */
@Service
public class WxPayConfig implements WXPayConfig {

    private byte[] certData;

    public WxPayConfig() throws Exception {
        String certPath = "C:\\kupa\\WxPayConfig\\apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public String getAppID() {
        return "wx34a3953f49ccb894";
    }

    public String getMchID() {
        return "1493827152";
    }

    public String getKey() {
        return "418206Abcd418206Abcd418206Abcd41";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }


}
